<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>天下行租车</title>
  <script src="http://47.106.66.89:8080/js/vue.min.js"></script>
  <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
  <link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
  <script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
  <link rel="stylesheet" href="css/base.css">
  <script src="js/txx.js" ></script>
</head>
<body>
<div id="app">
  <my-header></my-header>
  <main class="c900 el-card" style="align-items: stretch; width: 600px; padding: 30px 50px">
    <h2 style="text-align: center;margin-bottom: 50px">用户密码修改</h2>
    <el-row>
      <el-col :span="13" :offset="5">
        <el-form ref="form" label-width="90px">
          <el-form-item label="原密码">
            <el-input type="password" v-model="User.oldPwd"></el-input>
          </el-form-item>
          <el-form-item label="新密码">
            <el-input type="password" v-model="User.newPwd1"></el-input>
          </el-form-item>
          <el-form-item label="确认新密码">
            <el-input type="password" v-model="User.newPwd2"></el-input>
          </el-form-item>
          <el-form-item >
            <small style="color: red">{{errors.password}}</small>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="save">保存</el-button>
            <el-button @click="out">取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </main>
</div>
<script>
  var v = new Vue({
    el: "#app",
    data:{
      id:'',
      User:{oldPwd:'',newPwd1:'',newPwd2:''},
      errors:{password:''},

    },
    created(){
      this.id = location.search.replace("?id=","");
    },
    methods:{
      save(){
        this.errors={password:''}
        if(this.User.newPwd1 != this.User.newPwd2){
          this.errors.password = '两次输入的新密码不一致';
          return;
        }
        axios.get("txx/user/upPwd",{params:{id:this.id,oldPwd:this.User.oldPwd,newPwd:this.User.newPwd2}}).then(res=>{
          if(res.data.code == 1){
            alert("密码修改成功,\n用户信息已过期,请重新登录");
            location.href = "login.html";
          }else{
            this.errors.password = res.data.msg;
          }
        });
      },
      out(){
        window.history.back();
      }

    }
  })
</script>
</body>
</html>
<style>
  .el-form-item .el-form-item {
    margin-bottom: 22px
  }
</style>